package com.ss.android.article.common;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.webkit.WebChromeClient;
import android.webkit.WebViewClient;

import com.handmark.pulltorefresh.library.OverscrollHelper;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.ss.android.newmedia.webview.SSWebView;

public class PullToRefreshSSWebView extends PullToRefreshBase<SSWebView> {
    @TargetApi(value = 9)
    final class InternalWebViewSDK9 extends SSWebView {
        private final PullToRefreshSSWebView a;

        public InternalWebViewSDK9(PullToRefreshSSWebView arg1, Context arg2, AttributeSet arg3) {
            super(arg2, arg3);
            this.a = arg1;
        }

        protected final boolean overScrollBy(int arg11, int arg12, int arg13, int arg14, int arg15, int arg16, int arg17, int arg18, boolean arg19) {
            boolean v9 = super.overScrollBy(arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19);
            if (this.a.mIsReadyForPullStart) {
                OverscrollHelper.overScrollBy(this.a, arg11, arg13,
                        arg12, arg14,
                        Math.max(0, (((int) Math.floor(((double) (((SSWebView) this.a.getRefreshableView()).getScale()
                                * (((float) ((SSWebView) this.a.getRefreshableView()).getContentHeight())))))))
                                - (this.getHeight() - this.getPaddingBottom() - this.getPaddingTop())), 2, 1.5f, arg19);
            }
            return v9;
        }
    }

    protected boolean mIsReadyForPullStart;
    private static final OnRefreshListener defaultOnRefreshListener = new OnRefreshListener();
    private final WebChromeClient defaultWebChromeClient;
    private final WebViewClient defaultWebViewClient;

    public PullToRefreshSSWebView(Context context) {
        super(context);
        this.defaultWebChromeClient = new com.ss.android.article.common.ee(this);
        this.defaultWebViewClient = new com.ss.android.article.base.feature.app.browser.c();
        this.init();
    }

    public PullToRefreshSSWebView(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.defaultWebChromeClient = new com.ss.android.article.common.ee(this);
        this.defaultWebViewClient = new com.ss.android.article.base.feature.app.browser.c();
        this.init();
    }

    public PullToRefreshSSWebView(Context arg2, Mode arg3) {
        super(arg2, arg3);
        this.defaultWebChromeClient = new com.ss.android.article.common.ee(this);
        this.defaultWebViewClient = new com.ss.android.article.base.feature.app.browser.c();
        this.init();
    }

    public PullToRefreshSSWebView(Context arg2, Mode arg3, IAnimationStyle arg4) {
        super(arg2, arg3, arg4);
        this.defaultWebChromeClient = new com.ss.android.article.common.ee(this);
        this.defaultWebViewClient = new com.ss.android.article.base.feature.app.browser.c();
        this.init();
    }

    public final SSWebView createRefreshableView(Context arg3, AttributeSet arg4) {
        InternalWebViewSDK9 webViewSDK9 = new InternalWebViewSDK9(this, arg3, arg4);
        ((SSWebView) webViewSDK9).setId(com.ss.android.article.browser.R.id.webview);
        return webViewSDK9;
    }

    public final void onPtrRestoreInstanceState(Bundle bundle) {
        super.onPtrRestoreInstanceState(bundle);
        ((SSWebView) this.getRefreshableView()).restoreState(bundle);
    }

    public final boolean isReadyForPullStart() {
        this.mIsReadyForPullStart = this.getRefreshableView().getScrollY() == 0;
        return this.mIsReadyForPullStart;
    }

    public final void onPtrSaveInstanceState(Bundle bundle) {
        super.onPtrSaveInstanceState(bundle);
        ((SSWebView) this.getRefreshableView()).saveState(bundle);
    }

    public final boolean isReadyForPullEnd() {
        return this.getRefreshableView().getScrollY()
                >= (((int) Math.floor(((double) (((SSWebView) this.getRefreshableView()).getScale()
                * (((float) ((SSWebView) this.getRefreshableView()).getContentHeight()))))))) - this.getRefreshableView().getHeight();
    }

    public Orientation getPullToRefreshScrollDirection() {
        return Orientation.VERTICAL;
    }

    private void init() {
        this.setOnRefreshListener(PullToRefreshSSWebView.defaultOnRefreshListener);
        ((SSWebView) this.getRefreshableView()).setWebChromeClient(this.defaultWebChromeClient);
        ((SSWebView) this.getRefreshableView()).setWebViewClient(this.defaultWebViewClient);
    }
}

